package com.xbongbong.saas.script.tempenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.LinkDetailPojo;
import com.xbongbong.paas.help.FormDataFormExplainHelper;
import com.xbongbong.pro.enums.AmountFlagEnum;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.ForbiddenSettingEnum;
import com.xbongbong.saas.enums.RedundantTemplateTypeEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.PayPlanEnum;
import com.xbongbong.saas.enums.dictionary.HasRedEnum;
import com.xbongbong.saas.enums.dictionary.PayMethodEnum;
import com.xbongbong.saas.enums.dictionary.PayPlanStatusEnum;
import com.xbongbong.saas.enums.dictionary.PayTypeEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

import com.xbongbong.sys.enums.RoleEnum;
import lombok.Getter;

/**
 * @author feng.zheng
 * @version v1.0
 * @date 2019/1/16 20:35
 * @since v1.0
 */
@Getter
public enum TempPayPlanEnum {
    //刷脚本专用枚举

    BASE_INFO(PayPlanEnum.BASE_INFO),
    PAY_PLAN_NO(PayPlanEnum.PAY_PLAN_NO),
    LINK_SUPPLIER(PayPlanEnum.LINK_SUPPLIER),
    LINK_PURCHASE(PayPlanEnum.LINK_PURCHASE),
    AMOUNT(PayPlanEnum.AMOUNT),
    REAL_AMOUNT(PayPlanEnum.REAL_AMOUNT),
    UN_AMOUNT(PayPlanEnum.UN_AMOUNT),
    BAD_AMOUNT(PayPlanEnum.BAD_AMOUNT),
    INVOICE_AMOUNT(PayPlanEnum.INVOICE_AMOUNT),
    STATUS(PayPlanEnum.STATUS),
    BELONGER(PayPlanEnum.BELONGER),
    PAYMENT_METHOD(PayPlanEnum.PAYMENT_METHOD),
    PAY_TYPE(PayPlanEnum.PAY_TYPE),
    ESTIMATE_TIME(PayPlanEnum.ESTIMATE_TIME),
    MEMO(PayPlanEnum.MEMO),

    SYSTEM_INFO(PayPlanEnum.SYSTEM_INFO),
    CREATOR_ID(PayPlanEnum.CREATOR_ID),
    ADD_TIME(PayPlanEnum.ADD_TIME),
    UPDATE_TIME(PayPlanEnum.UPDATE_TIME),

    ADD_PAYPLAN(PayPlanEnum.ADD_PAYPLAN),
    REAL_PAY_TIME(PayPlanEnum.REAL_PAY_TIME),
    LINK_SUPPLIER_LINK_TEXT(PayPlanEnum.LINK_SUPPLIER_LINK_TEXT),
    LINK_PURCHASE_LINK_TEXT(PayPlanEnum.LINK_PURCHASE_LINK_TEXT),
    OWNER_ID(PayPlanEnum.OWNER_ID),
    COUSERID(PayPlanEnum.COUSERID),
    ;
    private PayPlanEnum anEnum;

    TempPayPlanEnum(PayPlanEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempPayPlanEnum> getAllEnum() {
        List<TempPayPlanEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    /**
     * 初始化付款计划编号
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initPayPlanNo(FieldAttrEntity fieldAttrEntity) {
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.PAY_PLAN.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.PAY_PLAN.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(PAY_PLAN_NO.getAnEnum().getAttr());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        fieldAttrEntity.setSerialNumber(InitExplainsHelper.setSerialNumber(SerialNumberEnum.PAY_PLAN_NO));
        fieldAttrEntity.setNoRepeat(1);
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化关联供应商
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initLinkSupplier(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.SUPPLIER.getCode());
        fieldAttrEntity.setLinkedText(LINK_SUPPLIER_LINK_TEXT.anEnum.getAttr());
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化关联采购单
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initLinkPurchase(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.PURCHASE.getCode());
        fieldAttrEntity.setLinkedText(LINK_PURCHASE_LINK_TEXT.anEnum.getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        saasParticularAttributePoJo.setRelyAttr(LINK_SUPPLIER.anEnum.getAttr());
        saasParticularAttributePoJo.setRelyBusiness(XbbRefTypeEnum.SUPPLIER.getCode());
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化付款状态
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initStatus(FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> itemPoJos = new ArrayList<>();
        Boolean checked=false;
        for (PayPlanStatusEnum payPlanStatusEnum : PayPlanStatusEnum.values()){
            if (Objects.equals(payPlanStatusEnum.getCode(),PayPlanStatusEnum.UNKNOWN.getCode())){
                continue;
            }
            ItemPoJo itemPoJo = new ItemPoJo();
            itemPoJo.setText(payPlanStatusEnum.getAlias());
            itemPoJo.setValue(payPlanStatusEnum.getCode());

            if (payPlanStatusEnum == PayPlanStatusEnum.UN_RECEIVABLES ) {
                itemPoJo.setShowType(ShowTypeEnum.ALL.getCode());
                checked=true;
            } else {
                itemPoJo.setShowType(ShowTypeEnum.EXCLUDE_NEW.getCode());
                checked=false;
            }
            itemPoJo.setChecked(checked);
            itemPoJos.add(itemPoJo);
        }
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setEditableAdvanceEnable(0);
        List<String> settingList = Arrays.asList(ForbiddenSettingEnum.DISABLE_ADVANCE_ENABLE.getAlias());
        fieldAttrEntity.setForbiddenSettingList(settingList);
        fieldAttrEntity.setItemBanDefault(BasicConstant.ONE);
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setItems(itemPoJos);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setNoItemLink(1);
    }

    /**
     * 初始化付款类型
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initPayType(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSetType(3);
        fieldAttrEntity.setRequired(0);
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(PayTypeEnum.class, fieldAttrEntity.getFieldType()));
        fieldAttrEntity.setDictionaryFlag(1);
    }


    public static void initAddPayPlan(FieldAttrEntity fieldAttrEntity) {
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setRelyAttr(LINK_PURCHASE.anEnum.getAttr());
        saasParticularAttributePoJo.setLinkBusinessType(XbbRefTypeEnum.PAY_PLAN.getCode());
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initAmount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(1);
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initRealAmount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(1);
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setShowEditable(0);
    }

    public static void initUnAmount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(1);
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setShowEditable(0);
    }

    public static void initEstimateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setDateType("yyyy-MM-dd");
        fieldAttrEntity.getDefaultAttr().setDefaultType("today");
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initRealPayTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setDateType("yyyy-MM-dd");
    }

    /**
     * 初始化支付方式
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     * @author long.rao
     * @date 2019-02-22 14:27
     */
    public static void initPaymentMethod(FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> items = InitExplainsHelper.setCombItemByEnum(PayMethodEnum.class, fieldAttrEntity.getFieldType());
        items.get(0).setChecked(true);
        fieldAttrEntity.setItems(items);
        fieldAttrEntity.setDictionaryFlag(1);
    }

    /**
     * 负责人
     * @param fieldAttrEntity
     */
    public static void initOwnerId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setShowType(ShowTypeEnum.ALL.getCode());
        fieldAttrEntity.setEditHide(0);
        fieldAttrEntity.setEditable(1);
        fieldAttrEntity.setMultiple(1);
        fieldAttrEntity.setIsForbidden(BasicConstant.ZERO);
        //可新增权限：默认【超级管理员、销售主管、创建人、负责人、负责人主管】可新增负责人，支持自定义；
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setAdd(1);
        fieldAttrEntity.setAddAdvanceEnable(1);
        fieldAttrEntity.setShowAdd(1);
        //可删除权限：默认【超级管理员、销售主管】可删除负责人，支持自定义；
        fieldAttrEntity.setRemove(1);
        fieldAttrEntity.setRemoveAdvanceEnable(1);
        fieldAttrEntity.setShowRemove(1);
        fieldAttrEntity.setAddRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
        fieldAttrEntity.setRemoveRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
    }

    /**
     * 初始化协同人字段
     *
     * @param fieldAttrEntity
     */
    public static void initCoUserId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setShowType(ShowTypeEnum.ALL.getCode());
        fieldAttrEntity.setFormPermission(BasicConstant.ONE);
        fieldAttrEntity.setIsForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setEditable(1);
        fieldAttrEntity.setSetType(3);
        //可新增权限：超级管理员、老板、销售主管、创建人、负责人、负责人主管
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setAdd(1);
        fieldAttrEntity.setAddAdvanceEnable(1);
        fieldAttrEntity.setShowAdd(1);
        fieldAttrEntity.setRemove(1);
        fieldAttrEntity.setRemoveAdvanceEnable(1);
        fieldAttrEntity.setShowRemove(1);
        fieldAttrEntity.setEditable(1);
        fieldAttrEntity.setUnableEditMemo(null);
        fieldAttrEntity.setAddRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
        fieldAttrEntity.setRemoveRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
    }

    public static void initCreatorId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initUpdateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    
    public static void initBadAmount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(1);
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setShowEditable(0);
    }
    
    public static void initInvoiceAmount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(1);
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setShowEditable(0);
    }
    public static void initHasRed(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(HasRedEnum.class, fieldAttrEntity.getFieldType()));
    }
}
